from django.db import models


# Create your models here.  User对应数据库中的表
class users(models.Model):
    account = models.CharField(max_length=15)
    password = models.CharField(max_length=200)
    name = models.CharField(max_length=15)
    emailbox = models.CharField(max_length=30)
    status = models.IntegerField()  # 只可以有三种值：1为管理员，2为教师，3为学生
    college = models.CharField(max_length=30)
    phonenumber = models.CharField(max_length=15)
    logstatus = models.BooleanField()  # boolean型只有两种值：0(false)为离线或登录过期，1(true)为登录且在线


class picture(models.Model):
    goods_pic = models.ImageField(upload_to='personalpic')
    user_account = models.CharField(max_length=15)


class Course(models.Model):
    Course_id = models.IntegerField(primary_key=True)  # 课程号
    name = models.CharField(max_length=20)  # 课程名
    credit = models.DecimalField(max_digits=2, decimal_places=1)  # 课程学分
    capacity = models.IntegerField()  # 课程容量
    teacher_id = models.IntegerField()  # 教师号
    teacher_name = models.CharField(max_length=10)  # 教师名
    term = models.CharField(max_length=10)  # 春 夏 秋 秋冬 春夏 短 冬
    year = models.IntegerField()  # 年份
    range = models.IntegerField()  # 课时
    # arrangeresult 不能修改


class TakeCourse(models.Model):
    Course_id = models.ForeignKey(Course, on_delete=models.CASCADE)  # 外键指向Course表的Course_id
    account = models.ForeignKey(users, on_delete=models.CASCADE)  # 外键指向users表的account


class ClassRoom(models.Model):
    # 教室唯一id
    ClassRoom_id = models.IntegerField(primary_key=True, unique=True)

    # 教室名字,如:208
    ClassRoom_Name = models.CharField(max_length=10)

    # 教室容量
    ClassRoom_Capacity = models.IntegerField()

    # 教学楼
    Teaching_Building = models.CharField(max_length=20)

    # 校区
    District = models.CharField(max_length=10)


class ArrangeResult(models.Model):
    # 课程唯一id
    # 外键 会自动在后面加上一个id
    Course = models.ForeignKey(Course, on_delete=models.CASCADE)

    # 教室唯一id
    ClassRoom = models.ForeignKey(ClassRoom, on_delete=models.CASCADE)

    # 课程开始
    Course_beg = models.IntegerField()

    # 课程结束
    Course_end = models.IntegerField()

    # 课程星期
    Course_week = models.IntegerField(default=1)


class SelectChooseClassTime(models.Model):
    id = models.IntegerField(primary_key=True, unique=True)  # 1 代表第一次选课开始时间和结束时间 2 代表第二次选课开始时间和结束时间
    start_date = models.DateTimeField(null=True)  # 开始时间
    end_date = models.DateTimeField(null=True)  # 结束时间


class TrainingProgram(models.Model):
    Course = models.ForeignKey(Course, on_delete=models.CASCADE)  # 外键指向Course表的Course_id
    account = models.ForeignKey(users, on_delete=models.CASCADE)  # 外键指向users表的account


# 现在余量
class NowCapacity(models.Model):
    Course_id = models.ForeignKey(Course, on_delete=models.CASCADE)  # 外键指向Course表的Course_id
    now_capacity = models.IntegerField()


# 选修必修课程
class CoreCourse(models.Model):
    Course = models.ForeignKey(Course, on_delete=models.CASCADE)  # 外键指向Course表的Course_id
    if_core = models.IntegerField()  # 1代表主修 2代表选修 3代表辅修
